package com.wutianyi.pool.concurrent;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;

public class ExecutorThreadPool {

	ExecutorService executorService = Executors.newFixedThreadPool(10);

	AtomicInteger count = new AtomicInteger();

	public <T> T executorTask(Callable<T> callable) {
		int cur_count = count.get();
		if (cur_count == 15) {
			return null;
		}
		count.getAndIncrement();
		
		Future<T> future = executorService.submit(callable);
		T t = null;
		try {
			t = future.get();
		} catch (InterruptedException e) {
		} catch (ExecutionException e) {
		} finally {
			count.decrementAndGet();
		}
		return t;
	}

	public static void main(String[] args) {
		
		AtomicInteger i = new AtomicInteger(1);
		System.out.println(i.get());
	}
}
